package com.lv.common.widget.scale

/**
 * 作者： ygx
 * 创建日期：2023/6/20 9:40 AM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 * -    _              _           _     _   ____  _             _ _
 * -   / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 * -  / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 * - / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 * -/_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 * <p>
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 * 描述：
 */

import android.view.MotionEvent
import android.view.View


/**
 * @Description:
 * @Author: JIULANG
 * @Data: 2022/5/12 18:44
 */
object TouchFeedbackUitl : View.OnTouchListener {
    /**
     * 缩放动画的单方面时长,假如是100,是指放大100,当手指离开缩小又是100.
     */
    private val duration = 100

    /**
     * 放大或者缩小的值
     */
    private val aFloatBig = 0.9f
    private val mTouchFeedback= TouchFeedback
    override fun onTouch(v: View, event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> mTouchFeedback.scaleBig(v)
            MotionEvent.ACTION_MOVE -> {
            }
            MotionEvent.ACTION_UP -> {
                if (isOutterUp(event, v)) {
                    event.action = MotionEvent.ACTION_CANCEL
                    return onTouch(v, event)
                }
                mTouchFeedback.scaleSmall(v, true)
                v.performClick()
            }
            MotionEvent.ACTION_CANCEL -> mTouchFeedback.scaleSmall(v, false)
        }
        return true
    }

    private fun isOutterUp(event: MotionEvent, v: View): Boolean {
        val touchX = event.x
        val touchY = event.y
        val maxX: Int = v.width
        val maxY: Int = v.height
        return touchX < 0 || touchX > maxX || touchY < 0 || touchY > maxY
    }
}
